#include <stdio.h>
#include <stdbool.h>

int input[100005][3] = {0};
int output[100005][3] = {0};
int index = 0;
int level_index = 0;

void swapArray(int data1[], int data2[]){
	int temp[3] = {0};
	temp[0] = data2[0];
	temp[1] = data2[1];
	temp[2] = data2[2];
	data2[0] = data1[0];
	data2[1] = data1[1];
	data2[2] = data1[2];
	data1[0] = temp[0];
	data1[1] = temp[1];
	data1[2] = temp[2];
}

void myInsertSort(int data[]){
	int sum = 0, i = 0;
	i = level_index;

	index++;
	do{
		sum = data[1] + data[2];
		//按总分排序
		if(output[i][1] + output[i][2] > sum){
			continue;
		}
		//当分数相同时，按德分排序
		else if(output[i][1] + output[i][2] == sum && output[i][1] > data[1]){
			continue;
		}
		//当分数相同且德分相同，按准考证号排序
		else if(output[i][1] + output[i][2] == sum && output[i][1] == data[1] && output[i][0] < data[0]){
			continue;
		}
		swapArray(data, output[i]);
	}while(i++ <= index);
}

int main()
{
	int num = 0, low = 0, high = 0;
	
	int i = 0;
	scanf("%d %d %d", &num, &low, &high);
	
	while(i <num){
		scanf("%d %d %d", &input[i][0], &input[i][1], &input[i][2]);
		i++;
	}
	//德才全尽
	for(i = 0; i < num; i++){
		if(input[i][1] >= high && input[i][2] >= high){
			myInsertSort(input[i]);
		}
	}
	level_index = index;
	//德才胜
	for(i = 0; i < num; i++){
		//德分高于优先分，才分低于优先分
		if(input[i][1] >= high && input[i][2] < high && input[i][2] >= low){
			myInsertSort(input[i]);
		}
	}
	//第三阶梯
	level_index = index;
	for(i = 0; i < num; i++){
		//德分和才分均低于优先分，但是德分不低于才分
		if(input[i][1] < high && input[i][2] < high && input[i][1] >= low && input[i][2] >= low){
			if(input[i][1] >= input[i][2]){
				myInsertSort(input[i]);
			}
		}
	}
	//第四阶梯
	level_index = index;
	for(i = 0; i < num; i++){
		if((input[i][1] < high || input[i][2] < high) && input[i][1] >= low && input[i][2] >= low){
			//这个第三阶梯的情况，跳过
			if(input[i][1] < high && input[i][2] < high && input[i][1] >= input[i][2]){
				continue;
			}
			//剩下的都是第四阶梯
			myInsertSort(input[i]);
		}
	}
	//排序后
	printf("%d\n", index);
	for(i = 0; output[i][0] != 0; i++){
		printf("%d %d %d\n", output[i][0], output[i][1], output[i][2]);
	}
	return 0;
}